package com.gaxy.subject.domain.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池config管理
 *
 * @author Gaxy
 * @create 2024/06/18/下午 08:00
 */
@Configuration
public class ThreadPoolConfig {

    @Bean(name = "labelThreadPool")
    public ThreadPoolExecutor getLabelThreadPool(){
        return new ThreadPoolExecutor(20,100, 5, TimeUnit.SECONDS,
                //使用LinkedBlockingDeque作为任务队列,队列长度40
                new LinkedBlockingDeque<>(40),
                new CustomNameThreadFactory("label"),
                //当线程池和队列都满时，使用CallerRunsPolicy策略
                new ThreadPoolExecutor.CallerRunsPolicy());
    }

}
